package com.itcast.manager2.D_dao;

import com.itcast.manager2.E_domain.Student;

import java.util.ArrayList;

public class StudentDao {
    ArrayList<Student> list = new ArrayList<Student>();

    public ArrayList<Student> getAllStudent() {
        return list;
    }

    public void addStudent(Student s) {
        list.add(s);
    }

    public void deleteStudent(String id) {
        Student stu = getStdentid(id);
            list.remove(stu);

    }


    public void updateStdent(Student stu) {
            Student ss = getStdentid(stu.getId());
                ss.setName(stu.getName());
                ss.setAge(stu.getAge());
                ss.setBirthday(stu.getBirthday());
        }


    public Student getStdentid(String id) {
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            if (stu.getId().equals(id)) {
                return stu;
            }
        }
        return null;
    }
}

